package com.lineage.server.command.executor;

import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class L1ChatListen implements L1CommandExecutor {
  private static final Log _log = LogFactory.getLog(L1ChatListen.class);
  
  public static L1CommandExecutor getInstance() {
    return new L1ChatListen();
  }
  
  public void execute(L1PcInstance pc, String cmdName, String arg) {
    try {
      int chat = Integer.parseInt(arg);
      try {
        switch (chat) {
          case 0:
            pc.setChatListenNormal(Boolean.FALSE);
            pc.setChatListenParty(Boolean.FALSE);
            pc.setChatListenClan(Boolean.FALSE);
            pc.setChatListenWhisper(Boolean.FALSE);
            pc.sendPackets((ServerBasePacket)new S_SystemMessage("关闭全部窃听模式。"));
            return;
          case 1:
            pc.setChatListenNormal(Boolean.TRUE);
            pc.setChatListenParty(Boolean.TRUE);
            pc.setChatListenClan(Boolean.TRUE);
            pc.setChatListenWhisper(Boolean.TRUE);
            pc.sendPackets((ServerBasePacket)new S_SystemMessage("开启窃听模式[全部]。"));
            return;
          case 2:
            if (pc.getChatListenNormal().booleanValue()) {
              pc.setChatListenNormal(Boolean.FALSE);
              pc.sendPackets((ServerBasePacket)new S_SystemMessage("关闭窃听模式[一般]。"));
            } else {
              pc.setChatListenNormal(Boolean.TRUE);
              pc.sendPackets((ServerBasePacket)new S_SystemMessage("开启窃听模式[一般]。"));
            } 
            return;
          case 3:
            if (pc.getChatListenWhisper().booleanValue()) {
              pc.setChatListenWhisper(Boolean.FALSE);
              pc.sendPackets((ServerBasePacket)new S_SystemMessage("关闭窃听模式[密语]。"));
            } else {
              pc.setChatListenWhisper(Boolean.TRUE);
              pc.sendPackets((ServerBasePacket)new S_SystemMessage("开启窃听模式[密语]。"));
            } 
            return;
          case 4:
            if (pc.getChatListenParty().booleanValue()) {
              pc.setChatListenParty(Boolean.FALSE);
              pc.sendPackets((ServerBasePacket)new S_SystemMessage("关闭窃听模式[队伍]。"));
            } else {
              pc.setChatListenParty(Boolean.TRUE);
              pc.sendPackets((ServerBasePacket)new S_SystemMessage("开启窃听模式[队伍]。"));
            } 
            return;
          case 5:
            if (pc.getChatListenClan().booleanValue()) {
              pc.setChatListenClan(Boolean.FALSE);
              pc.sendPackets((ServerBasePacket)new S_SystemMessage("关闭窃听模式[血盟]。"));
            } else {
              pc.setChatListenClan(Boolean.TRUE);
              pc.sendPackets((ServerBasePacket)new S_SystemMessage("开启窃听模式[血盟]。"));
            } 
            return;
        } 
        pc.sendPackets((ServerBasePacket)new S_SystemMessage(
              "窃听编号 [0=关闭全部,1=开启全部,2=一般,3=密语,4=队伍,5=血盟]"));
      } catch (Exception exception) {
        pc.sendPackets((ServerBasePacket)new S_SystemMessage(
              "窃听编号 [0=关闭全部,1=开启全部,2=一般,3=密语,4=队伍,5=血盟]"));
      } 
    } catch (Exception e) {
      _log.error("错误的GM指令格式: " + getClass().getSimpleName() + " 执行的GM:" + pc.getName());
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(261));
    } 
  }
}
